<?php

namespace App\Service\Kms\Common;

use App\Models\Kms\Album\AlbumResourceModel;

class AMapService
{

    /**
     * @param string $type
     * @return array
     */
    public static function getAMapPoiSearchCode(string $type = ""): array
    {
        $typeCodeGroup = [
            [
                "en"         => AlbumResourceModel::POI_TYPE_A_MAP_MALL,
                "cn"         => "购物",
                "searchCode" => ["060000"],
            ],
            [
                "en"         => AlbumResourceModel::POI_TYPE_A_MAP_FOOD_BEVERAGE,
                "cn"         => "餐饮",
                "searchCode" => ["050000"],
            ],
            [
                "en"         => AlbumResourceModel::POI_TYPE_A_MAP_HOUSING_ESTATE,
                "cn"         => "小区",
                "searchCode" => ["120000"],
            ],
            [
                "en"         => AlbumResourceModel::POI_TYPE_A_MAP_ENTERPRISE,
                "cn"         => "企业",
                "searchCode" => ["170000"],
            ],
            [
                "en"         => AlbumResourceModel::POI_TYPE_A_MAP_PLACE_NAME,
                "cn"         => "地名",
                "searchCode" => ["190000"],
            ],
        ];

        $typeCodeGroupCollection = collect($typeCodeGroup);
        if ($type && $typeDetail = $typeCodeGroupCollection->where("en", $type)->first()) {
            return [$typeDetail["searchCode"], $typeDetail];
        }
        $searchCode = [];
        $typeCodeGroupCollection->each(function ($v) use (&$searchCode) {
            $searchCode = array_merge($searchCode, $v["searchCode"]);
        });
        return [$searchCode, []];
    }
}
